package com.jt.tenant.conn;

import com.jt.tenant.app.JTApplication;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/14.
 */
@HttpInlet(Conn.INLET_DIAGNOSTIC_CAR)
public class GetDiagnosticCar extends JTAsyGet<GetDiagnosticCar.Info> {

    public String token = JTApplication.jtPreferences.readToken();

    public String obdid = JTApplication.jtPreferences.readOdbID();

    public GetDiagnosticCar(AsyCallBack<Info> asyCallBack) {

        super(asyCallBack);

    }

    @Override
    protected Info parser(JSONObject object) {

        JSONObject apiTYF = object.optJSONObject("apiTYF");

        JSONObject head = apiTYF.optJSONObject("head");

        Info info = new Info();

        info.msg = head.optString("msg");

        JSONObject body = apiTYF.optJSONObject("body");

        JSONObject total = body.optJSONObject("total");

        info.score = total.optString("score");

        info.scoreDate = total.optString("scoreDate");

        JSONArray array = total.optJSONArray("dtc");

        if (array != null) {

            for (int i = 0; i < array.length(); i++) {

                JSONObject o = array.optJSONObject(i);

                Detection detection = new Detection();

                detection.id = o.optString("id");

                detection.description = o.optString("title");

                detection.levle = o.optString("levle");

                detection.extent = o.optString("extent");

                detection.code = o.optString("code");

                detection.suggest = o.optString("suggest");

                info.list.add(detection);

            }

        }

        return info;

    }

    public static class Info {

        public String msg;

        public String score;

        public String scoreDate;

        public List<Detection> list = new ArrayList<>();

    }

    public static class Detection implements Serializable{

        public boolean isType = true;

        public String id;

        public String description, code, type;

        public String levle;

        public String extent;

        public String suggest;

        public int percent;

    }

}
